package display3d.alternativa
{
	import alternativa.engine3d.core.Face;
	import alternativa.engine3d.core.Vertex;
	import alternativa.engine3d.materials.FillMaterial;
	import alternativa.engine3d.materials.Material;
	import alternativa.engine3d.objects.Mesh;
	
	public class Pyramid3D extends Mesh
	{
		private var base:Face;
		private var sides:Vector.<Face>;
		
		
		public function Pyramid3D(width:Number=100, length:Number=100, height:Number=100,faces:int=4, material:Material=null)
		{
			super();
				
			if(!material) material = new FillMaterial(0xFF0000, 1, 1, 0x000000);
			
			var vectBase:Vector.<Vertex> = new Vector.<Vertex>();
			var top:Vertex = addVertex(0, -height/2, 0, 0, 0);
			
			sides = new Vector.<Face>();
			
			for(var i:int=0; i<faces; i++){
				var _x:Number = Math.cos(i*Math.PI/180*360/faces)*width/2;
				var _z:Number = Math.sin(i*Math.PI/180*360/faces)*length/2;
				var _y:Number = height/2;
				var vert:Vertex = addVertex(_x, _y, _z, 0, 0);
				vectBase.push(vert);
				
				if(i>0){
					sides.push(addFace(Vector.<Vertex>([vectBase[i-1], vectBase[i], top]),material));
				}
				
				if(i==faces-1){
					sides.push(addFace(Vector.<Vertex>([vectBase[faces-1], vectBase[0], top]),material));
				}
			}
						
			base = addFace(vectBase.reverse(), material);			
						
			calculateBounds();
		}
	}
}